package cn.edu.zafu.bigdata.x.wupeng.i;

public class ThreadDemo1 {

    public static void main2(String[] args) {
        System.out.println("main start...");
        Thread t = new Thread() {
            public void run() {
                System.out.println("thread run...");
                System.out.println("thread end.");
            }
        };
        t.start();
        try {
            Thread.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("main end...");
    }
    public static void main(String[] args) {
        System.out.println("Main Start");
        Thread t1 = new MyThread();
        t1.start();
        Thread t2 = new Thread(new MyRunnable());
        t2.start();
        //用lambda表达式实现一个线程,输出10次
        Thread t3 = new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                System.out.println("Hello Lambda.");
                try {
                    Thread.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        t3.start();
        System.out.println("Main End");
    }
}
class MyThread extends Thread{
    @Override
    public void run() {
        //下面一行输出10次
        for (int i = 0; i < 10; i++) {
            //System.out.println(i);
            System.out.println("Hello Thread.");
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
class MyRunnable implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            //System.out.println(i);
            System.out.println("Hello Runnable.");
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}